<?php
// 获取签名

function getSignature($str, $key) {  
    $signature = "";
       if (function_exists('hash_hmac')) {
           $signature = base64_encode(hash_hmac("sha1", $str, $key, true));
       } else {
           $blocksize = 64;
           $hashfunc = 'sha1';
           if (strlen($key) > $blocksize) {
               $key = pack('H*', $hashfunc($key));
           }
           $key = str_pad($key, $blocksize, chr(0x00));
           $ipad = str_repeat(chr(0x36), $blocksize);
           $opad = str_repeat(chr(0x5c), $blocksize);
           $hmac = pack(
               'H*', $hashfunc(
                   ($key ^ $opad) . pack(
                       'H*', $hashfunc(
                           ($key ^ $ipad) . $str
                       )
                   )
               )
           );
           $signature = base64_encode($hmac);
       }
       return $signature;
    
       
    
}

// urlencode();
// $time=urlencode(date("Y-m-d\TH:i:s\Z",time()));
// $cnos0=urlencode("cnos[0]");
// $cnos1=urlencode("cnos[1]");


// $urlParam="GETapi-bj.clink.cn/cc/list_clients?AccessKeyId=744b4a789bad71d638513bd2bde04696&Expires=600&Timestamp={$time}&limit=10&offset=0&qno=0000&{$cnos0}=0000&{$cnos1}=0001";

// $Signature=urlencode(base64_encode(getSignature("2AN549p3vCPBN8dMHTtc",$urlParam)));


// $url="https://api-bj.clink.cn/cc/list_clients?AccessKeyId=744b4a789bad71d638513bd2bde04696&Expires=600&Timestamp={$time}&limit=10&offset=0&qno=0000&{$cnos0}=0000&{$cnos1}=0001&Signature={$Signature}";

// var_dump($url);


function get_signature($type,$data){
    $consStr="";
    foreach($data as $k=>$v){
        $consStr.="&".$k."=".urlencode($v);
    } 
    $time=urlencode(date("Y-m-d\TH:i:s\Z",time()));
    $urlParam="{$type}api-bj.clink.cn/cc/download_record_file?AccessKeyId=744b4a789bad71d638513bd2bde04696&Expires=600&Timestamp={$time}{$consStr}";

    return [urlencode(getSignature("2AN549p3vCPBN8dMHTtc",$urlParam)),$urlParam];
}


$data=[
    "mainUniqueId"=>"8008370-20221108141833-17611740979-15726610082--record-medias_11-1667888313.62868",
];
$urlParam=get_signature("GET",$data);




var_dump($urlParam);